package com.ym.core.config;

import com.ym.core.interceptor.RepeatSubmitInterceptor;
import com.ym.core.interceptor.SignInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 向MVC中添加自定义组件
 */
@Component
public class WebMvcConfig implements WebMvcConfigurer {

	@Autowired
	private SignInterceptor signInterceptor;

	@Autowired
	private RepeatSubmitInterceptor repeatSubmitInterceptor;


	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(signInterceptor);
		registry.addInterceptor(repeatSubmitInterceptor);
	}


	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**").allowedMethods("GET", "POST");
	}
}
